import { Component, Input, Output } from '@angular/core';

import { Grid } from '../../../share/model/grid.model';

@Component({
  selector: 'app-grid',
  templateUrl: './grid.component.html',
  styleUrls: ['./grid.component.css']
})
export class GridComponent {


  @Input() grid: Grid;

  constructor() { }

  onChecked(item) {
    let flag = !item.checked;
    if (this.grid.singleSelect) {
      this.singleSelect(this.grid.data);
    }
    item.checked = flag;
  }

  private singleSelect(array) {
    array.forEach(e => {
      e.checked = false;
    });
  }

  autoWrap(column: any, row: any): any {
    return column.formatter ? column.formatter(row) : row[column.field];
  }


}
